<CFSETTING ENABLECFOUTPUTONLY="Yes">


<CFINCLUDE TEMPLATE="../../common/_toggle.cfm">

 <!--- Set default value for optional parameters --->
<CFPARAM NAME="url.desc" DEFAULT="">
<CFPARAM NAME="url.rf" DEFAULT="">
<CFPARAM NAME="url.autosubmit" DEFAULT="N">
<CFPARAM NAME="url.filter" DEFAULT="">
<CFPARAM NAME="url.nonull" DEFAULT="N">
<CFPARAM NAME="url.fldfn" DEFAULT="">
<CFPARAM NAME="url.flddesc" DEFAULT="">
<CFPARAM NAME="url.tllkup" DEFAULT="">
<CFPARAM NAME="url.tnlkup" DEFAULT="">
<CFPARAM NAME="url.joinfld1" DEFAULT="">
<CFPARAM NAME="url.joinfld2" DEFAULT="">
<CFPARAM NAME="url.flddesclkup" DEFAULT="">
<CFPARAM NAME="url.addvalue" DEFAULT="">
<CFPARAM NAME="url.tldsn" DEFAULT="">
<CFPARAM NAME="url.fldFilter" DEFAULT="">
<CFPARAM NAME="url.fldVal" DEFAULT="">
<CFPARAM NAME="url.deforder" DEFAULT="#url.fldfn#">
<CFSETTING ENABLECFOUTPUTONLY="No">

<html>
<head>
	<title>iBOS/e Lookup Dialog</title>
	<CFOUTPUT>
	<LINK REL="StyleSheet" HREF="../../webshell/themes/#client.empcolor#.css" TYPE="text/css">
	</CFOUTPUT>
	<script  language="JavaScript1.2">
	<!--
	function SetLookup(sRetVal, sRetDesc, sRetField) {
	<CFOUTPUT>
	var FieldDesc="#url.desc#", oFrm, aTemp, nCnt, aTempVal, sMultipleFN="#url.fn#"
		//FormName = "#url.frm#", FieldName = "#url.fn#",

		if ("#url.autosubmit#" == "Y") {
			//oFrm=eval("self.opener.document." + FormName)
			oFrm=self.opener.document.#url.frm#

			if ("#url.rf#" != "")
				oFrm.action=oFrm.action + ((oFrm.action.indexOf("?") == -1) ? "?" : "&") + "retval=" + sRetField

			oFrm.submit()
		} else {
			aTemp=sMultipleFN.split(",")

			for (nCnt=0; nCnt < aTemp.length; nCnt++) {

				if ("#url.addvalue#" != "") {

					sPrevVal=eval("self.opener.document.#url.frm#." + aTemp[nCnt] + ".value")

					if (sPrevVal == "")
						eval("self.opener.document.#url.frm#." + aTemp[nCnt] + ".value='" + sRetVal + "#url.addvalue#'")
					else
						eval("self.opener.document.#url.frm#." + aTemp[nCnt] + ".value='" + sPrevVal + sRetVal + "#url.addvalue#'")
				} else {

					eval("self.opener.document.#url.frm#." + aTemp[nCnt] + ".value='" + sRetVal + "'")

					}
			}

			if (FieldDesc != "") {

				aTemp=FieldDesc.split(",")
				aTempVal=sRetDesc.split("~")

				for (nCnt=0; nCnt < aTemp.length; nCnt++) {

					if (nCnt <= (aTempVal.length - 1))
						sExtraDesc=aTempVal[nCnt]
					else
						sExtraDesc=" "

					eval("self.opener.document.#url.frm#." + aTemp[nCnt] + ".value='" + sExtraDesc + "'")
				}
			}
		}

		window.close()
	</CFOUTPUT>
	}
	-->
	</script>
</head>
<body topmargin=0 rightmargin=0 leftmargin=0 bottommargin=0 bgcolor="#FFFFFF">
	<!--- Required Parameters:
		tl  - lookup table database level e.g. C, D, S, T
		tn  - lookup tablename e.g. CMFPA, CLKPOSITION
		rf  - field to be returned e.g. PERSONNELIDNO, DIVISIONCODE, UNITCODE
		frm - formname e.g. frmMainGraph, frmAdd, frmView
		fn  - form fieldname where selected lookup code will be place, can be multiple comma-delimited, allow null e.g. fldName, fldCode
		desc - form fieldname where selected lookup desc will be place, can be multiple comma-delimited, allow null e.g. fldDesc, fldTitle
		autosubmit - if Y will automatically submit form when code in lookup is selected otherwise will not
		filter - filter expression for lookup SQL statement e.g. GRAPHOWNER <> 'MHEL'
		fldprop - field property of fields to display and to be use for ordering, a list within a list,
			every button is separated by comma and each property is separated by ~
			syntax:  desc_of_field~fieldname~fieldtype, etc.
			e.g. Description~DESCRIPTION~ftstring,Chart Title~CHARTTITLE~ftstring,Owner~GRAPHOWNER~ftstring
		nonull - if Y will disable null value
		fldfn - code field to put in fn (must exist in fldprop), allow null
		flddesc - desc field to put in desc (must exist in fldprop), can be multiple comma-delimited, must be of same length with desc allow null
		tllkup - lookup description database level e.g.C,D,S,T (optional)
		tnlkup - lookup description tablename (optional)
		joinfld1 - lookup joining field (optional)
		joinfld2 - lookup descripition joining field (optional)
		flddesclkup - lookup description field (optional)
		addvalue - string to add before adding value (optional)
		deforder - default order for lookup
	 --->

	<!--- get table location --->
	<!--- custom tag: parameter: DBLEVEL; return value: DSN --->

	<CFIF url.tldsn EQ "">
		<CFMODULE TEMPLATE="../../common/cfm_leveldsn.cfm" DBLEVEL="#url.tl#">
		<CFSET table_dsn = DSN>
	<CFELSE>
		<CFSET table_dsn = url.tldsn>
	</CFIF>

	<CFIF url.tllkup NEQ "">
		<!--- get table location for lookup description --->
		<!--- custom tag: parameter: DBLEVEL; return value: DSN --->
		<CFMODULE TEMPLATE="../../common/cfm_leveldsn.cfm" DBLEVEL="#url.tllkup#">
		<CFSET description_dsn = DSN>
	</CFIF>

	<!--- Set constant for Order --->
	<CFSET cORDERDESC=1> <!--- Order Description --->
	<CFSET cORDERFN=2> <!--- Order Fieldname --->
	<CFSET cORDERTYPE=3> <!--- Order Columntype --->

	<CFSET sDelimiter="">
	<CFSET lIncluded="Yes">
	<CFSET lIncluded2="Yes">
	<CFSET lIncluded3="Yes">
	<CFSET popQuery = "">


	<CFLOOP LIST="#url.fldprop#" INDEX="x">
		<CFIF NOT listFindNoCase(popQuery,ListGetAt(x, cORDERFN, "~"))>

			<CFSET popQuery = popQuery & sDelimiter & ListGetAt(x, cORDERFN, "~")>
			<cfset rrr=#popQuery#>
		</CFIF>
		<CFSET sDelimiter=",">
		<CFSET sField=UCase(ListGetAt("#x#", cORDERFN, "~"))>

		<CFIF sField IS UCase(url.rf)>
			<CFSET lIncluded="No">
		</CFIF>
		<CFIF sField IS UCase(url.fldfn)>
			<CFSET lIncluded2="No">
		</CFIF>
		<CFIF sField IS ListFindNoCase(#url.flddesc#, sField)>
			<CFSET lIncluded3="No">
		</CFIF>
	</CFLOOP>

	<CFIF (url.rf IS NOT "") AND lIncluded>
		<CFIF NOT ListContainsNoCase(popQuery,url.rf)>
			<CFSET popQuery = popQuery & sDelimiter & url.rf>
			<CFSET lIncluded = #popQuery#>
		</CFIF>
	</CFIF>
	<CFIF lIncluded2>
		<CFIF NOT ListContainsNoCase(popQuery,url.fldfn)>
			<CFSET popQuery = popQuery & sDelimiter & url.fldfn>
			<CFSET lIncluded2 = #popQuery#>
		</CFIF>
	</CFIF>
	<CFIF (url.flddesc IS NOT "") AND lIncluded3>
		<CFIF NOT ListContainsNoCase(popQuery,url.flddesc)>
			<CFSET asasa =#popQuery#>
			<CFSET popQuery = popQuery & sDelimiter & url.flddesc>
			<CFSET lIncluded3 = #popQuery#>
		</CFIF>
	</CFIF>
	<cfset counter= 1>
	<CFQUERY NAME="QueryView" DATASOURCE="#table_dsn#">
		SELECT #popQuery#
		FROM #url.tn#

		<CFIF url.filter IS NOT "" AND ISDEFINED("url.filter")>
			WHERE #PreserveSingleQuotes(url.filter)#
			<CFSET sClause="AND">
		<CFELSE>
			<CFSET sClause="WHERE">
		</CFIF>
	
		<CFSET fldFilter="">
		<CFSET fldVal="">
		<CFIF isdefined("url.fldFilter") and url.fldFilter NEQ "" AND URL.fldFilter NEQ "undefined">
			<CFLOOP LIST ="#url.fldFilter#" INDEX="filterCnt">
				<CFMODULE TEMPLATE="../../common/get_default_value.cfm" EntryValue="#ListGetAt(url.fldVal,counter)#">
				#sClause# #filterCnt# '#sDefaultValue#'
				<cfset counter= counter + 1>
				<CFSET sClause="AND">
			</CFLOOP>
			<CFSET fldFilter=url.fldFilter>
			<CFSET fldVal=url.fldVal>
		</CFIF>

		<CFIF IsDefined("form.edtValFilter") AND form.edtValFilter IS NOT "" AND form.edtValFilter NEQ "undefined">
			#sClause# #form.cmbSort# LIKE '#form.edtValFilter#%'
		</CFIF>
		<CFIF IsDefined("url.fldapprove") AND url.fldapprove IS NOT "" AND url.fldapprove NEQ "undefined">
			#sClause# APPROVED = '#url.fldapprove#'
		</CFIF>
		<CFIF IsDefined("form.cmbSort")>
			ORDER BY #form.cmbSort# <CFIF IsDefined("form.ascdesc")>#form.ascdesc#</CFIF>
		<CFELSEIF isdefined("url.deforder") AND url.deforder NEQ "" AND URL.deforder NEQ "undefined">
			ORDER BY #url.deforder#
		</CFIF>
	</CFQUERY>


	<!--- Set query string for toolbar's activity --->
	<CFSET sQueryString="tl=" & url.tl &
		"&tn=" & url.tn &
		"&rf=" & url.rf &
		"&frm=" & url.frm &
		"&fn=" & url.fn &
		"&desc=" & url.desc &
		"&autosubmit=" & url.autosubmit &
		"&filter=" & URLEncodedFormat(url.filter) &
		"&fldprop=" & url.fldprop &
		"&nonull=" & url.nonull &
		"&fldfn=" & url.fldfn &
		"&flddesc=" & url.flddesc  &
		"&tllkup=" & url.tllkup  &
		"&tnlkup=" & url.tnlkup  &
		"&joinfld1=" & url.joinfld1  &
		"&joinfld2=" & url.joinfld2  &
		"&flddesclkup=" & url.flddesclkup &
		"&addvalue=" & url.addvalue &
		"&deforder=" & url.deforder &
		"&fldFilter=" & fldFilter &
		"&fldVal=" & fldVal>
	<CFOUTPUT>

	<form method="post" action="poplookup.cfm?#sQueryString#" name="lookup">
	</CFOUTPUT>
	<CFSET frmName="lookup">
	<CFSET lstOrder=url.fldprop>
	<CFIF NOT ISDEFINED("form.btnschedtype")>
		<CFOUTPUT>
		<table BGCOLOR="#client.color_appbody#" border=0 cellspacing=1 cellpadding=0 width="100%">
			<tr>
				<TD colspan="3" NOWRAP CLASS="boldwhite11" BGCOLOR="#client.color_apptitle#">
					&nbsp;&nbsp;Select Options
				</TD>
			</tr>
			<tr>
				<td nowrap>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Please Select Sched Type:&nbsp;&nbsp;</td>
				<td nowrap>
					<SELECT NAME="SchedType" SIZE="1">
						<OPTION VALUE="subtemp">SubTemporary</OPTION>
						<OPTION VALUE="temp">Temporary</OPTION>
						<OPTION VALUE="perm">Permanent</OPTION>
					</SELECT>
				</td><INPUT CLASS="bitbtn" TYPE="submit" NAME="btnBackAction" VALUE="Back">
				<td nowrap>
					<INPUT CLASS="bitbtn" TYPE="submit" NAME="btnschedtype" VALUE="Select">	
				</td>
			</tr>
			<tr>
				<td nowrap>
					
				</td>
			</tr>
			<TR>
				<TD HEIGHT=8 COLSPAN=4 BGCOLOR="#client.color_apptitle#"></TD>
			</TR>
		</table>
		</CFOUTPUT>
	<CFELSE>
		<CFMODULE TEMPLATE="../../common/cfm_wswindow.cfm" TITLE="#url.tn# #url.flddesclkup#">
		<CFINCLUDE TEMPLATE="../../common/toolbar.cfm">
	
		<table border=0 cellspacing=1 cellpadding=0 width="100%">
			<CFIF NOT QueryView.RecordCount>
				<tr><td>No records found in the current filter.</td></tr>
			<CFELSE>
				<CFOUTPUT>
				<tr bgcolor="#client.color_tblhead#">
					<CFLOOP LIST="#url.fldprop#" INDEX="x" DELIMITERS=",">
						<td nowrap class="boldwhite" height=18>&nbsp;#ListGetAt("#x#", cORDERDESC, "~")#</td>
					</CFLOOP>
				</tr>
				<CFIF url.nonull IS NOT "Y">
					<tr bgcolor="#client.color_tblset1#">
						<td nowrap height="20">
							&nbsp;
							<a href="javascript:SetLookup('', '', '')">&lt;null value&gt;</a>
						</td>
						<td nowrap>&nbsp;Clear current value</td>
	
						<CFSET nListLen=ListLen(#url.fldprop#) - 2>
						<CFLOOP INDEX="x" FROM="1" TO="#nListLen#">
						<td>&nbsp;</td>
						</CFLOOP>
					</tr>
				</CFIF>
				</CFOUTPUT>
	
				<CFOUTPUT QUERY="QueryView" STARTROW="#nStartrow#" MAXROWS="#Evaluate(nEndrow - nStartrow + 1)#">
				<tr bgcolor="#IIf(CurrentRow Mod 2, "client.color_tblset2", "client.color_tblset1")#" valign="top">
	
					<CFSET lFirst="Yes">
					<CFLOOP LIST="#url.fldprop#" INDEX="x" DELIMITERS=",">
						<td nowrap height=17>
							<CFSET sAnchor=Evaluate("QueryView." & ListGetAt("#x#", cORDERFN, "~"))>
							&nbsp;
							<CFIF lFirst>
								<CFIF url.fldfn IS "">
									<CFSET sCode   = "">
									<CFSET sLkDesc = "">
								<CFELSE>
	
									<CFSET sCode   = Evaluate("QueryView." & url.fldfn)>
									<CFIF ISDEFINED("URL.grpuser")>
										<CFINCLUDE TEMPLATE="cfm_getemailadd.cfm">
										<CFSET sCode   = lstMember>
									</CFIF>
									<CFSET sLkDesc = "">
									<CFSET sDelimiter="">
	
									<CFLOOP LIST="#url.flddesc#" INDEX="x">
	
										<CFSET vFld2Ret=Evaluate("QueryView." & #x#)>
										<CFIF IsDate(vFld2Ret) AND NOT IsNumericDate(vFld2Ret)>
											<CFSET vFld2Ret=DateFormat(vFld2Ret, "dd/mm/yy")>
										</CFIF>
	
										<CFSET sLkDesc = sLkDesc & sDelimiter & ReplaceList(vFld2Ret, "',~", ",")>
										<CFSET sDelimiter="~">
									</CFLOOP>
	
								</CFIF>
								<CFIF url.rf IS "">
									<CFSET sRetVal="">
								<CFELSE>
									<CFSET sRetVal = Evaluate("QueryView." & url.rf)>
								</CFIF>
	
								<CFIF url.tllkup IS "">
									<a href="javascript:SetLookup('#sCode#', '#sLkDesc#', '#sRetVal#')">#sAnchor#</a>
								<CFELSE>
									<CFQUERY NAME="qryDescription" DATASOURCE="#description_dsn#">
										SELECT #url.flddesclkup#
										FROM #url.tnlkup#
										WHERE #url.joinfld2# = '#Evaluate("QueryView." & url.joinfld1)#'
									</CFQUERY>
									<CFIF qryDescription.RecordCount>
										<CFSET sLkDesc2="">
										<CFLOOP LIST="#url.flddesclkup#" INDEX="itemFld">
											<CFSET vFld2Ret=Evaluate("qryDescription.#itemFld#")>
											<CFIF IsDate(vFld2Ret) AND NOT IsNumericDate(vFld2Ret)>
												<CFSET vFld2Ret=DateFormat(vFld2Ret, "dd/mm/yy")>
											</CFIF>
	
											<CFSET sLkDesc2=sLkDesc2 & vFld2Ret & " ">
										</CFLOOP>
										<a href="javascript:SetLookup('#sCode#', '#sLkDesc2#', '#sRetVal#')">#sLkDesc2#</a>
									<CFELSE>
										<a href="javascript:SetLookup('#sCode#', '#sLkDesc#', '#sRetVal#')">#sAnchor#</a>
									</CFIF>
								</CFIF>
							<CFELSE>
								#sAnchor#
							</CFIF>
						</td>
						<CFSET lFirst="No">
					</CFLOOP>
				</tr>
				</CFOUTPUT>
	
				<CFOUTPUT>
					<tr bgcolor="#client.color_tblfoot#">
						<td class="white" height=18 colspan="#ListLen(url.fldprop)#">
							&nbsp;&nbsp;Records:&nbsp;#nStartrow#-#nEndrow#&nbsp;&nbsp;of&nbsp;&nbsp;#QueryView.RecordCount#
						</td>
					</tr>
				</CFOUTPUT>
			</CFIF>
		</table>
		<CFMODULE TEMPLATE="../../common/cfm_wswindow.cfm" TOP="False">
	</CFIF>
	</form>


	<script>
		window.focus()
	</script>
</body>
</html>